<?php

/*
 * Copyright (C) 2014 abc
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Description of common
 *
 * @author abc
 */

namespace application;

final class commonview {

    private $apptemplatefile = false;
    private $apptemplatedata = false;

    public function __construct($apptemplatefile, $apptemplatedata) {
        $this->apptemplatefile = $apptemplatefile;
        $this->apptemplatedata = $apptemplatedata;
    }

    public function render() {
        if ((empty($this->apptemplatedata)) OR ( is_null($this->apptemplatedata)) OR ( $this->apptemplatedata == false)) :
            throw new \Exception('Chybí data pro šablonu!', 823);
        endif;
        if (file_exists($this->apptemplatefile)) :
            $templatedata = $this->apptemplatedata;
            $templatefile = $this->apptemplatefile;
            ob_start();
            extract($templatedata);
            include($templatefile);
            return ob_get_flush();
        else :
            throw new \Exception('Šablona neexistuje!', 82);
        endif;
    }

}
